package com.bqtv.sport.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import com.bqtv.sport.databinding.DialogSetGoodsRemarkBinding
import com.hjq.base.BaseDialog
import com.hjq.base.BottomSheetDialog

class SetGoodsRemarkDialog {
    class Builder(context: Context) : BaseDialog.Builder<Builder>(context) {
        var binding: DialogSetGoodsRemarkBinding =
            DialogSetGoodsRemarkBinding.inflate(
                LayoutInflater.from(context),
                FrameLayout(context),
                false
            )

        init {
            setContentView(binding.root)
            setData()
        }

        fun setData(): Builder {

            setOnClickListener(binding.ivClose, binding.tvConfirm)
            return this
        }

        override fun onClick(view: View) {
            super.onClick(view)

            when (view) {
                binding.ivClose -> {
                    dismiss()
                }

                binding.tvConfirm -> {
                    clickResult?.onAddClick(binding.etRemark.text.toString())
                }
            }
        }

        override fun createDialog(context: Context, themeId: Int): BaseDialog {
            val dialog = BottomSheetDialog(context, themeId)
            dialog.getBottomSheetBehavior().setSkipCollapsed(true)
            return dialog
        }

        var clickResult: ClickResult? = null

        interface ClickResult {
            fun onAddClick(string: String)
        }
    }
}